/*
 * Copyright 2020 Makani Technologies LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef AVIONICS_FIRMWARE_MONITORS_SERVO_TYPES_H_
#define AVIONICS_FIRMWARE_MONITORS_SERVO_TYPES_H_

#include <stdint.h>

#include "avionics/common/faults.h"
#include "avionics/firmware/drivers/mcp9800_types.h"
#include "avionics/firmware/monitors/analog_types.h"
#include "avionics/firmware/monitors/mcp9800_types.h"
#include "avionics/firmware/monitors/servo_analog_types.h"
#include "avionics/firmware/monitors/servo_mcp342x_types.h"
#include "avionics/firmware/monitors/servo_mcp9800_types.h"

typedef enum {
  kServoMonitorStatusClampNormal = 1 << 0,
  kServoMonitorStatusClampActive = 1 << 1,
} ServoMonitorStatus;

typedef enum {
  kServoMonitorWarning12v = 1 << 0,
  kServoMonitorWarning5v  = 1 << 1,
  kServoMonitorWarningClampResistorDisconnected = 1 << 2,
  kServoMonitorWarningLvA = 1 << 3,
  kServoMonitorWarningLvB = 1 << 4,
  kServoMonitorWarningServoVoltage = 1 << 5,
  kServoMonitorWarningServoCurrent = 1 << 6,
} ServoMonitorWarning;

typedef enum {
  kServoMonitorErrorClampFuseBlown = 1 << 0
} ServoMonitorError;

typedef struct {
  StatusFlags flags;
  ServoHardware revision;  // Deprecated.

  // MCP342X thermocouple monitors.
  uint32_t mcp342x_populated;
  int32_t mcp342x_data[kNumServoMcp342xMonitors];

  // MCP9800 ambient temperature monitors.
  uint32_t mcp9800_populated;
  float mcp9800_data[kNumServoMcp9800Monitors];

  // Analog voltage monitors.
  uint32_t analog_populated;
  float analog_data[kNumServoAnalogVoltages];
} ServoMonitorData;

#endif  // AVIONICS_FIRMWARE_MONITORS_SERVO_TYPES_H_
